package org.itboys.admin.common;

/**
 * 作者：zzq
 * 时间：2018/8/24
 * 描述：自定义异常枚举
 *              code和value 保持唯一
 *             抛异常的格式   throw new ErrorException(ExceptionEnum.COMMENEXCPTION.getValue());
 */
public enum ExceptionEnum {
    EXCPTION("系统异常",-1),
    AUTHEXCPTION("没有权限",3),
    TOKENEXCPTION("签名错误",1),
    COMMENEXCPTION("常见错误",2),
    MOBILEEXCPTION("手机号格式错误",4),
    DELETE_EMP_EXCPTION("员工信息被使用，不可删除",5);

    private int code;
    private String value;

    public static String exceptionStr(int code) {
        for (ExceptionEnum c : ExceptionEnum.values()) {
            if (c.getCode() == code) {
                return c.getValue();
            }
        }
        return null;
    }

    public static ExceptionEnum getExceptionEnum(String value) {
        for (ExceptionEnum c : ExceptionEnum.values()) {
            if (c.getValue() == value) {
                return c;
            }
        }
        return null;
    }

    ExceptionEnum(String value, int code) {
        this.value = value;
        this.code = code;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}
